package com.healthcloud.controller.modules.losewisdom;


import com.healthcloud.dto.req.losewisdom.LoseWisdomSingleChoiceAnswerDetailDto;
import com.healthcloud.dto.req.losewisdom.LoseWisdomSingleChoiceAnswerReq;
import com.healthcloud.dto.req.losewisdom.LoseWisdomSingleChoiceSaveReq;
import com.healthcloud.dto.vo.LoseWisdomSingleChoiceVo;
import com.healthcloud.entity.losewisdom.LoseWisdomSingleChoiceAnswerEntity;
import com.healthcloud.entity.losewisdom.LoseWisdomSingleChoiceEntity;
import com.healthcloud.service.losewisdom.LoseWisdomSingleChoiceAnswerDetailService;
import com.healthcloud.service.losewisdom.LoseWisdomSingleChoiceAnswerService;
import com.healthcloud.service.losewisdom.LoseWisdomSingleChoiceService;
import com.healthcloud.utils.ApiRes;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 失智老人筛查
 */
@Deprecated
@Controller
@RequestMapping("/lose/wisdom/screen")
public class LWScreeningController {

    private static String prefix = "losewisdom/screening";

    @Autowired
    private LoseWisdomSingleChoiceService loseWisdomSingleChoiceService;

    @Autowired
    private LoseWisdomSingleChoiceAnswerService loseWisdomSingleChoiceAnswerService;

    @Autowired
    private LoseWisdomSingleChoiceAnswerDetailService loseWisdomSingleChoiceAnswerDetailService;

    @GetMapping("/index")
    public String index(){
        return prefix + "/screening";
    }

    @ApiOperation("跳转至更多页面")
    @GetMapping("/more")
    public String more() {
        return prefix + "/more";
    }

    @ApiOperation("跳转至修改页面")
    @GetMapping("/toUpdate")
    public String toUpdate() {
        return prefix + "/update";
    }

    /**
     * 获取PHQ-9单选题题目
     * @return
     */
    @ApiOperation("获取PHQ-9单选题题目")
    @PostMapping("/single/choice/phq")
    @ResponseBody
    public ApiRes getPhqQuestion() {
        LoseWisdomSingleChoiceEntity entity = new LoseWisdomSingleChoiceEntity();
        entity.setTitle("PHQ-9");
        List<LoseWisdomSingleChoiceEntity> question = loseWisdomSingleChoiceService.queryList(entity);
        return ApiRes.success(question);
    }

    /**
     * 获取GAD-7单选题题目
     * @return
     */
    @ApiOperation("获取GAD-7单选题题目")
    @PostMapping("/single/choice/gad")
    @ResponseBody
    public ApiRes getGadQuestion() {
        LoseWisdomSingleChoiceEntity entity = new LoseWisdomSingleChoiceEntity();
        entity.setTitle("GAD-7");
        List<LoseWisdomSingleChoiceEntity> question = loseWisdomSingleChoiceService.queryList(entity);
        return ApiRes.success(question);
    }

    /**
     * 获取筛查评价列表
     * @param req 查询参数
     * @return
     */
    @ApiOperation("获取筛查情况列表")
    @PostMapping("/answer/score")
    @ResponseBody
    public ApiRes getAnswerList(LoseWisdomSingleChoiceAnswerReq req) {
        List<LoseWisdomSingleChoiceAnswerEntity> list = loseWisdomSingleChoiceAnswerService.queryList(req);
        return ApiRes.success(list);
    }

    /**
     * 保存PHQ/GAD筛查问卷答案
     * @param req
     * @return
     */
    @ApiOperation("保存PHQ/GAD筛查问卷答案")
    @PostMapping("/save")
    @ResponseBody
    public ApiRes save(@RequestBody LoseWisdomSingleChoiceSaveReq req) {
        loseWisdomSingleChoiceAnswerService.saveOrUpdateAnswer(req);
        return ApiRes.success();
    }

    /**
     * 获取问卷答案明细
     * @param id
     * @return
     */
    @ApiOperation("获取问卷答案明细")
    @PostMapping("/answer/detail")
    @ResponseBody
    public ApiRes getAnswerDetail(@RequestParam("id") Integer id) {
        List<LoseWisdomSingleChoiceAnswerDetailDto> dtoList = loseWisdomSingleChoiceAnswerDetailService.getDetailsByAnswerId(id);
        return ApiRes.success(dtoList);
    }

    /**
     * 更改PHQ/GAD筛查问卷答案
     * @param req
     * @return
     */
    @ApiOperation("更改PHQ/GAD筛查问卷答案")
    @PostMapping("/update")
    @ResponseBody
    public ApiRes update(@RequestBody LoseWisdomSingleChoiceSaveReq req) {
        loseWisdomSingleChoiceAnswerService.saveOrUpdateAnswer(req);
        return ApiRes.success();
    }

    /**
     * 删除PHQ/GAD筛查问卷答案
     * @param id
     * @return
     */
    @ApiOperation("删除PHQ/GAD筛查问卷答案")
    @PostMapping("/delete")
    @ResponseBody
    public ApiRes delete(Integer id) {
        loseWisdomSingleChoiceAnswerService.deleteAnswer(id);
        return ApiRes.success();
    }

}
